package emulator.hardware.nmos6502.commands;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.CommandSet;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.Operand;
import emulator.hardware.nmos6502.operands.*;

/** LDY (LoaD Y register)
 *  
 *  Affects Flags: S Z
 *  
 *  MODE           SYNTAX       HEX LEN TIM
 *  Immediate     LDY #$44      $A0  2   2
 *  Zero Page     LDY $44       $A4  2   3
 *  Zero Page,X   LDY $44,X     $B4  2   4
 *  Absolute      LDY $4400     $AC  3   4
 *  Absolute,X    LDY $4400,X   $BC  3   4+
 *  
 *  + add 1 cycle if page boundary crossed
 */
public class LDY implements Command {

	@Override
	public void execute(Cpu6502 cpu, Operand operand) throws EmulatorException {
		HwByte value = operand.getByte();
		cpu.setY(value);
		Flags6502 flags = cpu.getFlags();
		flags.setNZFromValue(value);
		cpu.setFlags(flags);
	}

	@Override
	public String getName() {
		return "LDY";
	}

	@Override
	public void register(CommandSet cset) {
		 cset.defineCommand(0xA0, this, new Immediate());
		 cset.defineCommand(0xA4, this, new ZeroPage());
		 cset.defineCommand(0xB4, this, new ZeroPageX());
		 cset.defineCommand(0xAC, this, new Absolute());
		 cset.defineCommand(0xBC, this, new AbsoluteX());
	}

}
